package com.sgzn.sgpay.web.controller;

import com.sgzn.sgpay.model.request.SgsDeviceQueryAddPreInfoRequest;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.model.response.vo.DeviceQueryAddPreInfoVo;
import com.sgzn.sgpay.service.SgsDeviceQueryAddPreInfoService;
import com.sgzn.sgpay.web.controller.base.MerchantBaseController;
import com.sgzn.sgpay.web.handle.AssembleCommonHandle;
import com.sgzn.sgpay.web.request.Impl.DeviceQueryAddPreInfoRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 设备新增前查询所需信息控制器
 * @author huangsenguang
 * @version Id: DeviceQueryAddPreInfoController.java, v 0.1 2018/5/19 17:58 huangsenguang Exp $$
 */
@Slf4j
@Controller
public class DeviceQueryAddPreInfoController extends MerchantBaseController {
    @Resource
    private SgsDeviceQueryAddPreInfoService sgsDeviceQueryAddPreInfoService;
    @Resource
    private AssembleCommonHandle assembleCommonHandle;

    /**
     * 设备新增前查询所需信息
     * @param request
     * @return
     */
    @RequestMapping("/merchant/queryAddPreInfo")
    @ResponseBody
    public SgsResultResponse<DeviceQueryAddPreInfoVo> queryAddPreInfo(DeviceQueryAddPreInfoRequest request) {
        super.setMchInfo(request);
        return this.sgsDeviceQueryAddPreInfoService.queryAddPreInfo(assembleSgsDeviceAvailCodeQueryRequest(request));
    }

    /**
     * 组装设备更新请求
     * @param deviceRequest
     * @return
     */
    private SgsDeviceQueryAddPreInfoRequest assembleSgsDeviceAvailCodeQueryRequest(DeviceQueryAddPreInfoRequest deviceRequest) {
        SgsDeviceQueryAddPreInfoRequest request = new SgsDeviceQueryAddPreInfoRequest();
        this.assembleCommonHandle.assemble(deviceRequest, request);
        request.setDeviceId(deviceRequest.getDeviceId());
        return request;
    }
}

